package com.tf8.treasure.service.impl;

import com.tf8.treasure.entity.MultiMedia;
import com.tf8.treasure.entity.MultiMediaExample;
import com.tf8.treasure.mapper.MultiMediaMapper;
import com.tf8.treasure.service.MultiMediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class MultiMediaServiceImpl implements MultiMediaService {

    @Autowired
    private MultiMediaMapper multiMediaMapper;


    @Override
    public List<MultiMedia> findByType(String type) {
        MultiMediaExample example = new MultiMediaExample();
        example.createCriteria().andResourceTypeEqualTo(type);
        List<MultiMedia> multiMedia = multiMediaMapper.selectByExample(example);
        return multiMedia;
    }

    @Override
    public MultiMedia findOneByResourceId(String resourceId) {
        if(StringUtils.isEmpty(resourceId)){
            return null;
        }
        MultiMediaExample example = new MultiMediaExample();
        example.createCriteria().andResourceIdEqualTo(resourceId);
        List<MultiMedia> multiMedia = multiMediaMapper.selectByExample(example);
        if(CollectionUtils.isEmpty(multiMedia)){
            return null;
        }
        return multiMedia.get(0);
    }

}
